package computacaografica;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class Legenda {

	private String[] dados;

	private BufferedImage imageBuffer;

	private Color background;

	private int largura, altura;

	private Color[] cores = { Color.BLUE, Color.GREEN, Color.RED, Color.YELLOW };

	public Legenda(String[] dados, int largura, int altura) {
		this.dados = dados;
		this.largura = largura;
		this.altura = altura;
		this.background = Color.WHITE;
		this.geraLegenda();
	}

	private void geraLegenda() {
		this.imageBuffer = new BufferedImage(this.largura, this.altura,
				BufferedImage.TYPE_INT_RGB);
		Graphics g = this.imageBuffer.createGraphics();
		g.setColor(this.background);
		g.fillRect(0, 0, this.largura, this.altura);

		int inicioY = 20;
		int espacoLeg = 10;
		for (int i = 0; i < this.dados.length; i++){
			g.setColor(cores[i]);
			g.fillRect(20, inicioY, 30, 30);
			g.setColor(Color.BLACK);
			g.drawString(dados[i], 60, inicioY+20);
			inicioY += 30 + espacoLeg;
		}
	}

	public BufferedImage getBuffer() {
		return this.imageBuffer;
	}

	public ImageIcon getImage() {
		return new ImageIcon(this.imageBuffer);
	}

}
